package com.grape.aspect;

import com.alibaba.fastjson.JSON;
import com.grape.enums.VerifyCodeEnum;
import com.grape.feign.UserFeign;
import com.grape.redis.service.IRedisService;
import lombok.AllArgsConstructor;
import org.apache.logging.log4j.util.Strings;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.List;

@Aspect
@Component
@AllArgsConstructor
public class OperateLogAspect extends CommonAspect {

    private final UserFeign userFeign;

    private final IRedisService redisService;

    @Pointcut(value = "execution(* com.grape.api.v1.*.*(..))")
    public void aopWebLog() {
    }

    @Around("aopWebLog()")
    public Object myLogger(ProceedingJoinPoint pjp) throws Throwable {
        List<String> ignoreUrls = JSON.parseArray(redisService.get(VerifyCodeEnum.OPERATE_LOG_IGNORE_URL.join(Strings.EMPTY)), String.class);
        return this.myLogger(pjp, sysOperateLog -> userFeign.insert(sysOperateLog), ignoreUrls);
    }
}
